package com.wtwd.campus.send;

import com.wtwd.campus.common.Constants;
import com.wtwd.campus.entity.Command;
import com.wtwd.campus.entity.MqMessage;
import com.wtwd.campus.entity.MqSetWorkMode;

public class DeviceWorkModeSender implements Sender {
    @Override
    public Command dealMessage(MqMessage mqMessage) {
        MqSetWorkMode mqSetWorkMode = (MqSetWorkMode)mqMessage.getObject();
        String imei = mqSetWorkMode.getImei();
        String commandNumber = mqSetWorkMode.getCommandNumber();
        String cmd = Constants.SET_WORK_MODE;
        Integer mode = mqSetWorkMode.getMode();
        Integer interval = mqSetWorkMode.getInterval();
        String modeStr = "m".concat(String.valueOf(mode));
        // 构建指令
        Command command = new Command();
        command.setImei(imei);
        command.setCommandNumber(commandNumber);
        command.setCmd(cmd);
        command.setStatus(Constants.COMMAND_NEED_SAVE);
        // 构建内容
        String content = "*".concat(Constants.MANUFACTURER_NAME).concat(",").concat(imei).concat(",").concat(cmd).concat(",").concat(commandNumber).concat(",")
                .concat(modeStr).concat(",").concat(String.valueOf(interval)).concat("#");
        command.setContent(content);
        return command;
    }
}
